package com.example.nutritionmanager

import android.annotation.SuppressLint
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
//noinspection UsingMaterialAndMaterial3Libraries
import androidx.compose.material.BottomNavigation
//noinspection UsingMaterialAndMaterial3Libraries
import androidx.compose.material.BottomNavigationItem
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Person
import androidx.compose.material.icons.filled.Star
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.navigation.NavController
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
//import com.example.nutritionmanager.profile.ProfileInfoScreen
import com.example.nutritionmanager.profile.ProfileScreen
import com.example.nutritionmanager.viewModels.UserProfileViewModel
import com.example.nutritionmanager.home.HomeScreen
import com.example.nutritionmanager.profile.ProfileInfoScreen


@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@Composable
fun MainScreen(navController: NavController) {
    var selectedTab by remember { mutableStateOf(0) }
    val userProfileViewModel: UserProfileViewModel = hiltViewModel()
    // 嵌套导航
    val nestedNavController = rememberNavController()
    Scaffold(
        bottomBar = {
            BottomNavigationBar(selectedTab, onTabSelected = { selectedTab = it })
        }
    ) {
        when (selectedTab) {
            0 -> {
                NavHost(navController = nestedNavController, startDestination = "home") {
                    composable("home") {
                        HomeScreen(
                            nestedNavController,
                        )
                    }
                }
            }
            1 -> AIScreen(navController)
            2 -> {
                NavHost(navController = nestedNavController, startDestination = "profileScreen") {
                    composable("profileScreen") {
                        ProfileScreen(navController = nestedNavController)
                    }
//                    composable("profileInfo") {
//                        ProfileInfoScreen(navController = nestedNavController, viewModel = userProfileViewModel)
//                    }
                }
            }            // 使用嵌套 NavHost 来管理 ProfileScreen 的导航栈
        }
    }
}
@Composable
fun BottomNavigationBar(selectedTab: Int, onTabSelected: (Int) -> Unit) {
    BottomNavigation(
        modifier = Modifier.fillMaxWidth(),
//        backgroundColor = Color(0xFFf1f1f1),  // 设置背景为灰色
        backgroundColor = MaterialTheme.colorScheme.surface
    ) {
        BottomNavigationItem(
            selected = selectedTab == 0,
            onClick = { onTabSelected(0) },
            label = { Text("首页", color = MaterialTheme.colorScheme.onSurface) },
            icon = {
                Icon(
                    Icons.Default.Home,
                    contentDescription = "首页",
                    tint = if (selectedTab == 0) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurface // 选中时为绿色，否则为默认颜色
                )
            }
        )
        BottomNavigationItem(
            selected = selectedTab == 1,
            onClick = { onTabSelected(1) },
            label = { Text("AI", color = MaterialTheme.colorScheme.onSurface) },
            icon = {
                Icon(
                    Icons.Default.Star,
                    contentDescription = "AI",
                    tint = if (selectedTab == 1) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurface
                )
            }
        )
        BottomNavigationItem(
            selected = selectedTab == 2,
            onClick = { onTabSelected(2) },
            label = { Text("我的", color = MaterialTheme.colorScheme.onSurface) },
            icon = {
                Icon(
                    Icons.Default.Person,
                    contentDescription = "我的",
                    tint = if (selectedTab == 2) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurface
                )
            }
        )
    }
}